var express = require('express');
var router = express.Router();
var superagent = require('superagent');
var logger = require('../log4j').logger;
var logger_error = require('../log4j').logger_error;

/* GET home page. */
router.get('/daren_tang', function(req, res, next) {
  var isApp = req.query.isApp;
  if(isApp == 'yes'){
    if (req.query.DEVICE== 'ios') {
      isApp = 'ios';
    }else{
      isApp = 'android';
    }
  }
  var thisUrl = req.url;
  var shareUrl = encodeURIComponent((global.browserURL +'/daren'+thisUrl).split('#')[0]);
  console.log('shareUrl.................'+(global.browserURL +'/daren'+thisUrl).split('#')[0]);
  logger.info('shareUrl.................'+(global.browserURL +'/daren'+thisUrl).split('#')[0]);
  superagent
  .get(global.wechatURL + '/wechat_api/jsconfig?url=' + shareUrl)
  .end(function(err2, res2) {
    if (res2 !== undefined && res2.ok) {
      res2.body.browserUrl = global.browserURL;
      res2.body.flag = isApp;
      res.render('daren/tang',res2.body);
    } else {
      console.error('微信分享api错误。');
      logger_error.error('微信分享api错误。');
    }
  });
});

module.exports = router;;
